<?php
abstract class XA_Db_Table {

	public $table_name;
	public $field_list = array();
	public $primary_key_list = array();
	public $error_list = array();
	public $auto_increment_field;


	public function __construct($table_name) {
		$this->table_name = $table_name;
	}


	abstract public function count($row);
	abstract public function update($row);
	abstract public function insert($row);



	public function filter($row, $pk_only = false) {
		$field_name_list = $pk_only ? $this->primary_key_list : array_keys($this->field_list);

		foreach (array_keys($row) as $field) {
			if (!in_array($field, $field_name_list)) {
				unset($row[$field]);
			}
		}

		return $row;
	}



	public function replace($row) {
		return $this->save($row);
	}



	public function save($row) {
		if ($this->exists($row, true)) {
			return $this->update($row);
		} else {
			return $this->insert($row);
		}
	}
}
